/*

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; version 2
 of the License.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
#import "Settings.h"

#ifdef __OBJC2__
#define DEFAULTS_FILE @"/var/mobile/Library/Preferences/com.s4v4g3.iphone-xbmc-controller.plist"
#else
#define DEFAULTS_FILE @"/var/root/Library/Preferences/com.s4v4g3.iphone-xbmc-controller.plist"
#endif

static Settings *sharedInstance = nil;

@implementation Settings

+ (Settings *) sharedInstance {
	return ( sharedInstance ? sharedInstance : ( sharedInstance = [[self alloc] init] ) );
}

- (id) init
{
   self = [super init];
   
   // load defaults:
   [self loadDefaults];
	
	return self;
}

-(NSString*)getIPAddress
{
   return [m_defaults valueForKey:@"ipAddress"];
}

-(void)setIPAddress:(NSString*)value
{
   return [m_defaults setValue:value forKey:@"ipAddress"];
}

- (void)loadDefaults
{
    m_defaults = [[NSMutableDictionary alloc] initWithContentsOfFile: DEFAULTS_FILE];
    if (m_defaults == nil) {
        m_defaults = [[NSMutableDictionary alloc] init];
        // set defaults
        [m_defaults setValue:@"192.168.1.110" forKey:@"ipAddress"];
		[self save];
    }
}

-(void)save
{
    // save to file
    if (! [m_defaults writeToFile: DEFAULTS_FILE atomically: YES]) {
        NSLog(@"Could not write defaults");
    }
	
}


@end

